package com.jz.community.basecomm.utils;

import android.content.Context;

import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.MaterialDialog;

/**
 * @author weilu
 * author weilu on 2017年1月24日16:13:19
 */
public class DialogUtils {

    public DialogUtils(Context context, int title) {
        final MaterialDialog dialog = new MaterialDialog(context);
        dialog.content(context.getString(title)).btnText("取消", "确定").show();
        dialog.setOnBtnClickL(
                new OnBtnClickL() {//left btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        mOnDialogClickListener.onLeftClick();
                    }
                },
                new OnBtnClickL() {//right btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        mOnDialogClickListener.onRightClick();
                    }
                }
        );

    }

    public DialogUtils(Context context, String title) {
        final MaterialDialog dialog = new MaterialDialog(context);
        dialog.content(title).btnText("取消", "确定").show();
        dialog.setOnBtnClickL(
                new OnBtnClickL() {//left btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        mOnDialogClickListener.onLeftClick();
                    }
                },
                new OnBtnClickL() {//right btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        mOnDialogClickListener.onRightClick();
                    }
                }
        );
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
    }
    public DialogUtils(Context context, String title,String leftBtn,String rightBtn) {
        final MaterialDialog dialog = new MaterialDialog(context);
        dialog.content(title).btnText(leftBtn,rightBtn).show();
        dialog.setOnBtnClickL(
                new OnBtnClickL() {//left btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        mOnDialogClickListener.onLeftClick();
                    }
                },
                new OnBtnClickL() {//right btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        mOnDialogClickListener.onRightClick();
                    }
                }
        );
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
    }

    private OnDialogClickListener mOnDialogClickListener;

    public void setOnDialogClickListener(OnDialogClickListener mOnDialogClickListener) {
        this.mOnDialogClickListener = mOnDialogClickListener;
    }

    public interface OnDialogClickListener {
        void onLeftClick();

        void onRightClick();
    }

}
